package com.huawei.od.c.easy.t1;

import java.util.Arrays;

public class T1 {
    public static void main(String[] args) {
        int height = 100;
        int[] arr = {102, 103, 104, 95, 96, 97, 98, 99, 101, 105};
        t1(height, arr);
    }

    private static void t1(int height, int[] arr) {
        int[] arr_height = new int[arr.length];
        for (int i = 0; i < arr.length; i++) {
            arr_height[i] = arr[i] - height;
        }
        for (int i = 0; i < arr_height.length - 1; i++) {
            for (int j = i + 1; j < arr_height.length; j++) {
                if (
                        //身高绝对值比较大的 或者 身高绝对值一样 但是身高比较大的在前面 则需要调换位置
                        Math.abs(arr_height[i]) > Math.abs(arr_height[j])
                                || (Math.abs(arr_height[i]) == Math.abs(arr_height[j]) && (arr_height[i] > arr_height[j]))
                ) {
                    int temp1 = arr_height[i];
                    arr_height[i] = arr_height[j];
                    arr_height[j] = temp1;

                    int temp2 = arr[i];
                    arr[i] = arr[j];
                    arr[j] = temp2;
                }
            }
        }
        System.out.println(Arrays.toString(arr));
    }
}
